//
//  ZBTableviewHeadView.m
//  MoBan
//
//  Created by apple on 16/7/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZBTableviewHeadView.h"
@interface ZBTableviewHeadView()
@property(nonatomic,strong)UIImageView *imageview;
@property(nonatomic,strong)UILabel *lable;
@property(nonatomic,strong)UILabel *detaillable;
@property(nonatomic,strong)UIImageView *imageRightView;
@property(nonatomic,assign)BOOL isopen;
@end
@implementation ZBTableviewHeadView
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self =[super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self addUI];
        [self setUIfram];
    }
    return self;

}
/**
 添加控件
 */
-(void)addUI
{
    self.imageview = [[UIImageView alloc]init];
    self.imageview.image = [UIImage imageNamed:@"text.png"];
    [self.contentView addSubview:self.imageview];
    
    self.lable = [[UILabel alloc]init];
    [self.contentView addSubview:self.lable];
    
    self.detaillable = [[UILabel alloc]init];
    [self.contentView addSubview:self.detaillable];
    
    self.imageRightView = [[UIImageView alloc]init];
    self.imageRightView.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:self.imageRightView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headviewClic:)];
    [self.contentView addGestureRecognizer:tap];
    
    self.isopen = NO;

}
/**
 设置fram
 */
-(void)setUIfram
{
    self.imageview.frame = CGRectMake(10*Kscr, 10*Kscr, 40*Kscr, 40*Kscr);
    self.lable.frame = CGRectMake(self.imageview.right +10*Kscr, 20*Kscr, 300*Kscr, 20*Kscr);
    self.detaillable.frame = CGRectMake(self.imageview.right+10*Kscr, self.lable.bottom+5*Kscr, 300*Kscr, 20*Kscr);
    self.imageRightView.frame = CGRectMake(KscrW-30*Kscr, 20*Kscr, 10*Kscr, 20*Kscr);

}
//传入数据
-(void)getDatasouce:(NSString *)str WithSection:(NSInteger)section isopen:(BOOL)isopen
{
    self.isopen = isopen;
    self.lable.text = str;
    self.tag =section;
}
-(void)headviewClic:(UIGestureRecognizer*)tap
{
//    ZBTableviewHeadView *headview =(ZBTableviewHeadView *)tap.view;
//    self.isopen = NO;
    if ([self.deleget respondsToSelector:@selector(tableviewHeadView:didSelectSection:)]) {
        [self.deleget tableviewHeadView:self didSelectSection:self.tag];
    }

}
-(void)didMoveToSuperview
{
//    NSLog(@"hahah");
    
    if (self.isopen) {
        self.imageRightView.transform = CGAffineTransformMakeRotation(M_PI_2);

    }else
    {
        self.imageRightView.transform = CGAffineTransformMakeRotation(0);

    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
